package com.ymatou.iapi.prodstock.testcase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonElement;
import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.AgentPriceDto;
import com.shop2cn.iapi.agentproducts.parameter.CatalogDto;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymatou.iapi.godmch.parameter.AgentTypeVo;
import com.ymatou.iapi.godmch.parameter.listagentTypeBean;
import com.ymatou.iapi.liveseller.parameter.ActivityProductDto;
import com.ymatou.iapi.liveseller.parameter.CreateLiveActivityBean;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.LiveActivityDto;
import com.ymatou.iapi.prodstock.parameter.PCatalogListDto;
import com.ymatou.iapi.prodstock.parameter.PreOrderReduceCatalogDtoV2;
import com.ymatou.iapi.prodstock.parameter.ReduceStockListForPreOrderBean;
import com.ymatou.iapi.prodstock.service.ReduceStockListForPreOrderCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmongosync.service.EsCall;
import com.ymatou.iapi.productmongosync.service.MongocrudCall;
import com.ymatou.iapi.productquery.parameter.GetProductInfoByProductIdBean;
import com.ymatou.iapi.productquery.service.GetProductInfoByProductIdCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.database.RedisDriver;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallService;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.ProdStockCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.mongo.jproduct.ActivityProductsWapper;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

public class Ts_ReduceStockListForPreOrder {
	// default data
	private static String sellerName = EnvSetup.getData("autotest_sellerName1");
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static int sellerId1 = Integer.parseInt(EnvSetup.getData("productpriceSellerId"));
	private static int sellerId2 = Integer.parseInt(EnvSetup.getData("productsellerid"));

	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	private static ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();
	private static YmtProductActivityStockWapper ymtProductActivityStockWapper = new YmtProductActivityStockWapper();

	private static ReduceStockListForPreOrderCall reduceStockListForPreOrderCall;
	private static ReduceStockListForPreOrderBean reduceStockListForPreOrderBean;
	private static YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
	private static List<String> productlist;

	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
	private static IntergratedProductMapper ipm = SqlMapperFactory.getIntergratedProductMapper();

	//渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	//渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	//渠道商->代理商2
	private static int agentUserId2 = AgentUsers.agentUserId2;
	private static String agentUserName2 = "NickautoTest";

	//vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	//vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	//vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("预下单扣减库存");
		try {
			GodfreightmgrService.deleteBySellerId(rootUserId);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() throws ClientProtocolException, IOException, Exception {
		// ProductManagerCallServiceV2.batchSetProductOffSale(ProductManagerCallServiceV2.getProducts(sellerId,
		// 0),sellerId);
		reduceStockListForPreOrderCall = new ReduceStockListForPreOrderCall();
		reduceStockListForPreOrderBean = new ReduceStockListForPreOrderBean();
		productlist = new ArrayList<>();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(reduceStockListForPreOrderCall.getOpurl());
	}

	@After
	public void caseDown() throws Exception {
		Logger.debug("下架商品");
		ProductManagerCallServiceV2.updateActivityStock0(productlist);
		ProductManagerCallServiceV2.batchSetProductOffSale(productlist, sellerId);
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	@Deprecated
	public void Tc_ReduceStockListForPreOrder_001() {
		Logger.start(true, "普通现货商品,扣减库存");
		try {
			Logger.comment("第一次执可能出现上架商品数超出的限制问题,查询一些商品下架下架商品");
//			 ProductManagerCallServiceV2.offSaleAllProduct(sellerId);
			//
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int reduceNum = 2;

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, reduceNum, 0, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum - reduceNum, 0);

			// 扣库存 幂等
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, reduceNum, 0, catalogListDto.getBuyerId(),
					catalogListDto.getPreOrderId(), true, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto1, catalogNum - reduceNum, 0);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	@Deprecated
	public void Tc_ReduceStockListForPreOrder_002() {
		Logger.start(true, "活动商品,没有限购,扣减库存");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			// 活动库存
			int actNum = 10;
			Logger.debug(catalogs);
			Thread.sleep(5000);
			//ProductManagerCallServiceV2.addActivity(productId, sellerId, catalogs, activityId.toString(), actNum);
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, actNum,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			String catalogId = catalogs.get(0);
			int reduceNum=2;
			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, activityId, reduceNum, 0, true);

			// Thread t=new Thread();
			// t.sleep(10000);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum-actNum, actNum - reduceNum);

			// 扣库存 幂等
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, activityId, reduceNum, 0, catalogListDto.getBuyerId(),
					catalogListDto.getPreOrderId(), true, true);

			// check
			ProdStockCallService.checkReduceStock(catalogListDto1, catalogNum-actNum, actNum - reduceNum);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	@Deprecated
	public void Tc_ReduceStockListForPreOrder_003() {
		Logger.start(true, "活动商品,活动限购,扣减库存,成功");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			// 活动库存
			int actNum = 10;
			Logger.debug(catalogs);
			Thread.sleep(5000);
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, actNum,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);

			//ProductManagerCallServiceV2.addActivity(productId, sellerId, catalogs, activityId.toString(), actNum);

			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			String catalogId = catalogs.get(0);
			productlist.add(productId);
			// 扣库存数量
			int reduceNum = 2;

			// 修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(activityId, 0, 3);

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, activityId, reduceNum, 0, buyerId, true);
			// check 商品库存为扣去活动库存 活动库存为扣去真实库存
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum - actNum, actNum - reduceNum);

			// 换一个规格
			String catalogId2 = catalogs.get(1);
			int reduceNum2 = 2;
			int actNum2 = ymtProductActivityStockWapper.selectByCatalogId(catalogId2).getIstocknum();

			// 扣库存
			PCatalogListDto catalogListDto2 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId2, sellerId, activityId, reduceNum2, 0, true);
			// check 扣成功
			ProdStockCallService.checkReduceStock(catalogListDto2, catalogNum - actNum2, actNum2 - reduceNum2);

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	@Deprecated
	public void Tc_ReduceStockListForPreOrder_004() {
		Logger.start(true, "活动商品,活动商品限购,扣减库存,成功");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			// 活动库存
			int actNum = 10;
			Logger.debug(catalogs);
			Thread.sleep(5000);
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, actNum,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			String catalogId = catalogs.get(0);
			productlist.add(productId);
			// 扣库存数量
			int reduceNum = 2;

			// 修改活动限购数量 活动商品限购
			ProdStockCallService.updateActivityLimit(activityId, 1, 3);

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, activityId, reduceNum, 0, buyerId, true);
			// check 商品库存为扣去活动库存 活动库存为扣去真实库存
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum - actNum, actNum - reduceNum);

			// 换一个规格
			String catalogId2 = catalogs.get(1);
			int reduceNum2 = 2;
			int actNum2 = ymtProductActivityStockWapper.selectByCatalogId(catalogId2).getIstocknum();

			// 扣库存
			PCatalogListDto catalogListDto2 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId2, sellerId, activityId, reduceNum2, 0, true);
			// check 扣成功
			ProdStockCallService.checkReduceStock(catalogListDto2, catalogNum - actNum2, actNum2 - reduceNum2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_005() {
		Logger.start(true, "普通FBX商品,扣减库存");
		try {
			Map<String, Object> jsonbean = new HashMap<>();
			jsonbean.put("sellerId", sellerId);
			jsonbean.put("sellerName", sellerName);

			jsonbean.put("product->onSaleType", 0);
			jsonbean.put("product->catalogStatus", 2);
			jsonbean.put("product->productName", "自动化测试_立即上架商品 " + YMTDateUtil.getSysTime("yyyyMMddHHmmss"));
			String productId = ProductManagerCallServiceV2.addNewProductOnSale(sellerId, sellerName, null);
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int reduceNum = 2;

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, reduceNum, 2, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum - reduceNum, 0);

			// 扣库存 幂等
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, reduceNum, 2, catalogListDto.getBuyerId(),
					catalogListDto.getPreOrderId(), true, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto1, catalogNum - reduceNum, 0);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_006() {
		Logger.start(true, "FBX活动商品,扣减库存,没有限购");
		try {
			//String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();

			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum1 = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum1);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());

			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);

			productlist.add(productId);
			// 修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId, 2);

			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int reduceNum = 2;

			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, aid, reduceNum, 2, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, actNum - reduceNum);

			// 扣库存 幂等
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, aid, reduceNum, 2, catalogListDto.getBuyerId(),
					catalogListDto.getPreOrderId(), true, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto1, catalogNum, actNum - reduceNum);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_007() {
		Logger.start(true, "FBX活动商品,活动限购,扣减库存 ");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			//String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum1 = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum1);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());

			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			productlist.add(productId);
			// 修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId, 2);

			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int reduceNum = 2;

			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());

			// 修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(aid, 0, 3);

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, aid, reduceNum, 2, buyerId, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, actNum - reduceNum);

			// 第一个商品 不同买家下单
			YmtCatalogsI ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId2 = ymtCatalog2.getsCatalogId();
			int catalogNum2 = ymtCatalog2.getiNum();
			int reduceNum2 = 2;
			int actNum2 = ymtProductActivityStockWapper.selectByCatalogId(catalogId2).getIstocknum();

			// 扣库存
			PCatalogListDto catalogListDto2 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId2, sellerId, aid, reduceNum2, 2, true);
			// check 扣成功
			ProdStockCallService.checkReduceStock(catalogListDto2, catalogNum2, actNum2 - reduceNum2);

			/////////////////////////////////////////////////////////////////////
			// 第二个商品报名 同一个买家下单
			Map<String, Object> jsonbean = new HashMap<>();
			jsonbean.put("sellerId", sellerId);
			jsonbean.put("sellerName", sellerName);

			jsonbean.put("product->onSaleType", 0);
			jsonbean.put("product->catalogStatus", 7);
			jsonbean.put("product->productName", "自动化测试_立即上架商品 " + YMTDateUtil.getSysTime("yyyyMMddHHmmss"));
			AddSellerProductRequest addpro1 = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId3 = ProductManagerCallServiceV2.addNewProduct(addpro1).get("Data").getAsJsonObject().get("ProductId").getAsString();
			List<String> catalogs1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId3).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			productlist.add(productId3);
			// 报名
			//AdminCallService.applyAndApproveInActivity(aid, sellerId, productId3);
			//报名活动  获得商品在活动中的id
			List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(productId3, sellerId,catalogs1,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId3,aids1.get(0),true);

			// 修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId3, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId3, 2);

			YmtCatalogsI ymtCatalog3 = ymtCatalogsIWapper.selectCatalogsByProductId(productId3).get(0);
			String catalogId3 = ymtCatalog3.getsCatalogId();
			int catalogNum3 = ymtCatalog3.getiNum();
			int reduceNum3 = 2;
			int actNum3 = ymtProductActivityStockWapper.selectByCatalogId(catalogId3).getIstocknum();

			// 扣库存
			PCatalogListDto catalogListDto3 = ProdStockCallService.ReduceStockListForPreOrder(productId3, catalogId3, sellerId, aid, reduceNum3, 2, buyerId, false);
			// check 超限购 没有扣成功
			ProdStockCallService.checkReduceStock(catalogListDto3, catalogNum3, actNum3, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_008() {
		Logger.start(true, "FBX活动商品,活动商品限购,扣减库存");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			// 活动库存
			int actNum = 100;
			Logger.debug(catalogs);
			Thread.sleep(5000);
		//	ProductManagerCallServiceV2.addActivity(productId, sellerId, catalogs, activityId.toString(), actNum);
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, actNum,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			String catalogId = catalogs.get(0);
			
			// 修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId, 2);

			int reduceNum = 2;


			// 修改活动限购数量 活动商品限购
			ProdStockCallService.updateActivityLimit(activityId, 1, 3);

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, activityId, reduceNum, 2, buyerId, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum-actNum, actNum - reduceNum);


		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	/*@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	@Deprecated
	public void Tc_ReduceStockListForPreOrder_009() {
		Logger.start(true, "普通现货商品,已删除规格不能扣减库存");
		try {
			Logger.comment("第一次执可能出现上架商品数超出的限制问题,查询一些商品下架下架商品");
			ProductManagerCallServiceV2.offSaleAllProduct(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProductOnSale(sellerId, sellerName, null);
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int reduceNum = 2;

			// 已删除
			CIWapper.updateiActionByCatalogId(-1, ymtCatalog.getsCatalogId());
			// 同步monogo、es
			EsCall esCall = new EsCall();
			MongocrudCall mongoCall = new MongocrudCall();
			esCall.callAndGetReturnData(MapUtil.hashMap("ProductId", productId, "ActionType", "ModifyProduct", "TransactionId", TestDataManager.getRandomIntNum(5)));
			mongoCall.callAndGetReturnData(MapUtil.hashMap("ProductId", productId, "ActionType", "ModifyProduct", "TransactionId", TestDataManager.getRandomIntNum(5)));

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, reduceNum, 0, false);
			// check
			// ProdStockCallService.checkReduceStock(catalogListDto,catalogNum,0);
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, 0, false);
			// 扣库存 幂等
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, 0, 0, catalogListDto.getBuyerId(),
					catalogListDto.getPreOrderId(), false, true);
			// check
			// ProdStockCallService.checkReduceStock(catalogListDto1,catalogNum,0);
			ProdStockCallService.checkReduceStock(scatalogListDto1, catalogNum, 0, false);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}*/

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	@Deprecated
	public void Tc_ReduceStockListForPreOrder_009() {
		// 传了活动id扣活动库存 不传活动id已删除扣减失败 已删除规格不能扣减库存
		Logger.start(true, "活动商品,没有限购,传了活动id扣活动库存");
		try {
			//String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum1 = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum1);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());

			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int reduceNum = 2;
			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());

			// 已删除
			CIWapper.updateiActionByCatalogId(-1, ymtCatalog.getsCatalogId());
			// 同步mongo、es
			EsCall esCall = new EsCall();
			MongocrudCall mongoCall = new MongocrudCall();
			esCall.callAndGetReturnData(MapUtil.hashMap("ProductId", productId, "ActionType", "ModifyProduct", "TransactionId", TestDataManager.getRandomIntNum(5)));
			mongoCall.callAndGetReturnData(MapUtil.hashMap("ProductId", productId, "ActionType", "ModifyProduct", "TransactionId", TestDataManager.getRandomIntNum(5)));

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, aid, reduceNum, 0, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, actNum - reduceNum);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_010() {
		// 传了活动id扣活动库存 不传活动id已删除扣减失败 已删除规格不能扣减库存
		Logger.start(true, "活动商品,没有限购,没传活动id扣活动库存扣减失败");
		try {
			//String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum1 = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum1);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());

			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int reduceNum = 2;
			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());

			// 已删除
			CIWapper.updateiActionByCatalogId(-1, ymtCatalog.getsCatalogId());
			// 同步mongo、es
			EsCall esCall = new EsCall();
			MongocrudCall mongoCall = new MongocrudCall();
			esCall.callAndGetReturnData(MapUtil.hashMap("ProductId", productId, "ActionType", "ModifyProduct", "TransactionId", TestDataManager.getRandomIntNum(5)));
			mongoCall.callAndGetReturnData(MapUtil.hashMap("ProductId", productId, "ActionType", "ModifyProduct", "TransactionId", TestDataManager.getRandomIntNum(5)));

			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, reduceNum, 0, false);
			// check
			// ProdStockCallService.checkReduceStock(catalogListDto, catalogNum,
			// actNum);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	@Deprecated
	public void Tc_ReduceStockListForPreOrder_011() {
		Logger.start(true, "活动商品,活动限购,扣减库存,超限失败");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());

			//报名活动  获得商品在活动中的id
			int actNum = 10;
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, actNum,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			String catalogId = catalogs.get(0);
			productlist.add(productId);

			int limit = 3;
			// 修改活动限购数量 活动商品限购
			ProdStockCallService.updateActivityLimit(activityId, 1, limit);
			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, activityId, limit + 1, 0, buyerId, false);
			// check 超限购 没有扣成功
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum-actNum, actNum, false);
		} catch (Exception e) {
			Logger.fail(e);
		}

	}


	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_013() {
		Logger.start(true, "秒杀活动商品,扣减库存");
		try {
			Logger.comment("创建商品");
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			//CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 6d, 6, starttime);
			
			CreateLiveActivityBean createliveactivityBean = new CreateLiveActivityBean();
			LiveActivityDto LiveActivity=new LiveActivityDto();
			List<ActivityProductDto> ActivityProducts=new ArrayList<>();
			ActivityProductDto activityProductDto = new ActivityProductDto();
			activityProductDto.setProductId(productId);
			activityProductDto.setActivityPrice(7d);
			activityProductDto.setActivityStock(100);
			activityProductDto.setCatalogId(cids.get(0));
			ActivityProducts.add(activityProductDto);
			
			LiveActivity.setActivityProducts(ActivityProducts);
			LiveActivity.setStartTime(String.valueOf(starttime.getTime()));
			LiveActivity.setEndTime(String.valueOf(starttime.getTime()+1*60*1000));
			LiveActivity.setLiveId(createlive.getId());
			LiveActivity.setSellerId(sellerId);
			createliveactivityBean.setLiveActivity(LiveActivity);
			
			createliveactivityBean.getLiveActivity().setActivityProducts(ActivityProducts);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			LiveRoomWapper LiveRoomWapper = new LiveRoomWapper();
			//直播秒杀活动id
			Integer liveacctivityid = LiveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
			Long OrderID = System.currentTimeMillis();
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(liveacctivityid);
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			preOrderReduceCatalogDto.setBuyCount(10);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(cids.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(cids.get(0)).getIstocknum();
			//商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum-activityProductDto.getActivityStock(), icatalogNum, "验证规格库存");
			Logger.verifyEquals(activityProductDto.getActivityStock()-preOrderReduceCatalogDto.getBuyCount(), istocknum, "验证活动库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_014() {
		Logger.start(true, "普通现货商品,扣减库存");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			preOrderReduceCatalogDto.setBuyCount(100);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			//商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum-preOrderReduceCatalogDto.getBuyCount(), icatalogNum, "验证规格库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_015() {
		Logger.start(true, "活动商品,没有限购,扣减库存");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			Integer istocknum = ymtProductActivityStockWapper.selectByCatalogId(catalogs.get(0)).getIstocknum();
			Long OrderID = System.currentTimeMillis();
			
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(activityId);
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			preOrderReduceCatalogDto.setBuyCount(100);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			Integer istocknum1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			//商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum-istocknum, icatalogNum, "验证规格库存");
			Logger.verifyEquals(istocknum-preOrderReduceCatalogDto.getBuyCount(), istocknum1, "验证活动库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_016() {
		Logger.start(true, "活动商品,活动限购,扣减库存,成功");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			Integer istocknum = ymtProductActivityStockWapper.selectByCatalogId(catalogs.get(0)).getIstocknum();
			Long OrderID = System.currentTimeMillis();
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			// 修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(activityId, 0, 30);
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(activityId);
			preOrderReduceCatalogDto.setBuyCount(20);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			//活动库存
			Integer istocknum1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			//商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum-istocknum, icatalogNum, "验证规格库存");
			Logger.verifyEquals(istocknum-preOrderReduceCatalogDto.getBuyCount(), istocknum1, "验证活动库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_017() {
		Logger.start(true, "活动商品,活动商品限购,扣减库存,成功");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			Integer istocknum = ymtProductActivityStockWapper.selectByCatalogId(catalogs.get(0)).getIstocknum();
			Long OrderID = System.currentTimeMillis();
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			// 修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(activityId, 1, 30);
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(activityId);
			preOrderReduceCatalogDto.setBuyCount(20);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			//活动库存
			Integer istocknum1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			//商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum-istocknum, icatalogNum, "验证规格库存");
			Logger.verifyEquals(istocknum-preOrderReduceCatalogDto.getBuyCount(), istocknum1, "验证活动库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_018() {
		Logger.start(true, "普通现货商品,已删除规格不能扣减库存");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			// 已删除
			CIWapper.updateiActionByCatalogId(-1, catalogs.get(0));
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			preOrderReduceCatalogDto.setBuyCount(100);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("201", Code, "验证Code");
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum, icatalogNum, "验证规格库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_019() {
		// 传了活动id扣活动库存 不传活动id已删除扣减失败 已删除规格不能扣减库存
		Logger.start(true, "活动商品,没有限购,传了活动id扣活动库存");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			// 已删除
			CIWapper.updateiActionByCatalogId(-1, catalogs.get(0));
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			preOrderReduceCatalogDto.setBuyCount(100);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("201", Code, "验证Code");
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum, icatalogNum, "验证规格库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_020() {
		Logger.start(true, "活动商品,活动限购,扣减库存,超限失败");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			Integer activityNum = 100;
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, activityNum,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			Long OrderID = System.currentTimeMillis();
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			// 修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(activityId, 0, 30);
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(activityId);
			preOrderReduceCatalogDto.setBuyCount(100);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("201", Code, "验证Code");
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum-activityNum, icatalogNum, "验证规格库存");
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(activityNum, istocknum, "验证活动库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_021() {
		Logger.start(true, "活动商品,活动商品限购,扣减库存,超限失败");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			Integer activityNum = 100;
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, activityNum,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			Long OrderID = System.currentTimeMillis();
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			// 修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(activityId, 1, 30);
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(activityId);
			preOrderReduceCatalogDto.setBuyCount(40);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("201", Code, "验证Code");
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum-activityNum, icatalogNum, "验证规格库存");
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(activityNum, istocknum, "验证活动库存");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	/**
	 * 代购神器
	 */

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_024() {
		Logger.start(true, "微信代购商品,渠道商,扣减库存,扣减成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,rootUserName,false);
			Integer catalogNum = 10000;
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum);
			});
		 	String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<YmtCatalogsI> ymtCatalogsIList = new YmtCatalogsIWapper().selectCatalogsByProductId(productId);
			int reduceNum = 10;
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, ymtCatalogsIList.get(0).getsCatalogId(), sellerId, 0, reduceNum, 0, true);
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum - reduceNum, 0);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_022() {
		Logger.start(true, "微信代购商品,代理商下单,扣减库存,扣减成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,rootUserName,true);
			Integer catalogNum = 10000;
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum);
			});
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,rootUserId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			int reduceNum = 10;
			List<YmtCatalogsI> ymtCatalogsIList = new YmtCatalogsIWapper().selectCatalogsByProductId(agentProductId);
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(agentProductId, ymtCatalogsIList.get(0).getsCatalogId(), agentUserId1, 0, reduceNum, 0, true);
			YmtCatalogsI rootYmtCatalog = new YmtCatalogsIWapper().selectCatalogsByCatalogId(ymtCatalogsIList.get(0).getsCatalogId());
			//验证代理商库存为0
			ProdStockCallService.checkReduceStock(catalogListDto, 0, 0);

			catalogListDto.setCatalogId(rootYmtCatalog.getParentCatalogId());
			catalogListDto.setProductId(productId);
			//验证渠道商商品库存
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum - reduceNum, 0);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_023() {
		Logger.start(true, "微信代购商品,三级代理,扣减库存,扣减成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			Integer catalogNum = 10000;
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum);
			});
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);

			//渠道商->代理
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId2,vipAgentUserName2,agentProductId,vipAgentUserId1,false);

			//渠道商->代理->代理
			String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);
			int reduceNum = 10;
			List<YmtCatalogsI> ymtCatalogsIList = new YmtCatalogsIWapper().selectCatalogsByProductId(agentProductId1);
			//扣减库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(agentProductId1, ymtCatalogsIList.get(0).getsCatalogId(), vipAgentUserId2, 0, reduceNum, 0, true);
			//验证代理商2库存为0
			ProdStockCallService.checkReduceStock(catalogListDto, 0, 0);
			//代理商2的规格
			YmtCatalogsI agentYmtCatalog2 = new YmtCatalogsIWapper().selectCatalogsByCatalogId(ymtCatalogsIList.get(0).getsCatalogId());
			catalogListDto.setProductId(agentProductId);
			catalogListDto.setCatalogId(agentYmtCatalog2.getsCatalogId());
			catalogListDto.setSellerId(vipAgentUserId1);
			//验证代理商1的库存
			ProdStockCallService.checkReduceStock(catalogListDto, 0, 0);
			YmtCatalogsI agentYmtCatalog = new YmtCatalogsIWapper().selectCatalogsByCatalogId(ymtCatalogsIList.get(0).getRootCatalogId());
			catalogListDto.setProductId(productId);
			catalogListDto.setCatalogId(agentYmtCatalog.getsCatalogId());
			catalogListDto.setSellerId(vipRootUserId);
			//验证渠道商的库存
			ProdStockCallService.checkReduceStock(catalogListDto,catalogNum-reduceNum, 0);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_025() {
		Logger.start(true, "普通现货商品,库存低于购买数量，不能购买，库存不变，返回400");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 2;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			preOrderReduceCatalogDto.setBuyCount(100);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("400", Code, "验证Code，已经没货");
			//商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum, icatalogNum, "验证规格库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_026() {
		Logger.start(true, "限时抢，预下单扣减库存");
		try {
			//创建商品，设置初始库存，
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,rootUserName,false);
			Integer catalogNum11 = 10000;
			
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum11);
			});
		 	String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
		 	//根据数据库查询
		 	ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(rootUserId,productId);
		 	System.out.println(selectProductDetails);
		 	
		 	//获取购买前商品规格库存
			Integer catalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer catalogNum1 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(1).getiNum();
			System.out.println(catalogNum+"    "+catalogNum1);
			
			
			//创建限时抢购活动
			List<String> catalogList =new ArrayList<String>();
			
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			AddactivityBean initProductaddactivity = AgentProductCallService.initProductaddactivity(rootUserId, productId, catalogList);
			
			int activityId = AgentProductCallService.agentProductaddactivity(initProductaddactivity);
		
			//减去5库存
			int reduceNum = 5;
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(0), rootUserId, activityId, reduceNum, 0, true);
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(1), rootUserId, activityId, reduceNum, 0, true);
			
			
			System.out.println("aaaa"+catalogListDto);
			ProductDetailsDto selectProductDetails1 = AddAgentProductCallService.selectProductDetails(rootUserId,productId);
			
			
			//获取商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer icatalogNum1 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(1).getiNum();
			System.out.println(icatalogNum+"    "+icatalogNum1);
			
			System.out.println(selectProductDetails1);
			Logger.verifyEquals(catalogNum, selectProductDetails.getCatalogList().get(0).getStock(), "活动库存为0");
			Logger.verifyEquals(catalogNum, selectProductDetails.getCatalogList().get(1).getStock(), "活动库存为0");
			Logger.verifyEquals(catalogNum, selectProductDetails1.getCatalogList().get(0).getStock()+5, "活动库存为0");
			Logger.verifyEquals(catalogNum, selectProductDetails1.getCatalogList().get(1).getStock()+5, "活动库存为0");
			Logger.verifyEquals(catalogNum, icatalogNum+5, "规格1库存验证");
			Logger.verifyEquals(catalogNum1, icatalogNum1+5, "规格2库存验证");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_027() {
		Logger.start(true, "限时抢，库存扣完时，没有活动信息");
		try {
			//创建商品，设置初始库存，
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,rootUserName,false);
			Integer catalogNum11 = 10000;
			
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum11);
			});
		 	String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
		 	//根据数据库查询
		 	ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(rootUserId,productId);
		 	System.out.println(selectProductDetails);
		 	
		 	//获取购买前商品规格库存
			Integer catalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer catalogNum1 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(1).getiNum();
			System.out.println(catalogNum+"    "+catalogNum1);
			
			//创建限时抢购活动
			List<String> catalogList =new ArrayList<String>();
			
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			AddactivityBean initProductaddactivity = AgentProductCallService.initProductaddactivity(rootUserId, productId, catalogList);
			
			int activityId = AgentProductCallService.agentProductaddactivity(initProductaddactivity);
		
			//减去所有库存
			int reduceNum =10000;
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(0), rootUserId, activityId, reduceNum, 0, true);
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(1), rootUserId, activityId, reduceNum, 0, true);
			
			
			ProductDetailsDto selectProductDetails1 = AddAgentProductCallService.selectProductDetails(rootUserId,productId);
			Thread.sleep(2000);
			GetProductInfoByProductIdBean b=new GetProductInfoByProductIdBean();
			b.setNextActivityExpire(7);
			b.setProductId(productId);
			GetProductInfoByProductIdCall c=new GetProductInfoByProductIdCall();
			c.setData(b);
			c.callService();
			
			JsonElement aa = c.getJsonObject().get("Data").getAsJsonObject().get("Product").getAsJsonObject().get("ProductActivity");		
			//获取商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer icatalogNum1 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(1).getiNum();
			System.out.println(icatalogNum+"    "+icatalogNum1);
			Logger.verifyEquals(true,aa.isJsonNull(), "库存为0时活动数据不存在");
//			Logger.verifyEquals(null, aa, "库存为0时活动数据不存在");
			Logger.verifyEquals(0, icatalogNum, "库存为0");
			Logger.verifyEquals(0, icatalogNum1, "库存为0");
			System.out.println(selectProductDetails1);
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_028() {
		Logger.start(true, "普通现货商品,扣减库存-多个商品规格");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			
			//创建商品
			AddSellerProductRequest addpro2 = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum2 = 1000;
			addpro2.getProduct().getCatalogList().forEach(catalog2 -> {
				catalog2.setStock(catalogNum2);
			});
			
			//获取商品ID
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addpro2).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs2 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId2).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			
			
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			preOrderReduceCatalogDto.setBuyCount(100);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto2 = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto2.setActivityId(0);
			preOrderReduceCatalogDto2.setActivityLimitNumber(0);
			preOrderReduceCatalogDto2.setBuyCount(100);
			preOrderReduceCatalogDto2.setBuyerId(buyerId);
			preOrderReduceCatalogDto2.setCatalogId(catalogs2.get(0));
			preOrderReduceCatalogDto2.setCatalogType(0);
			preOrderReduceCatalogDto2.setProductId(productId2);
			preOrderReduceCatalogDto2.setProductLimitNumber(0);
			preOrderReduceCatalogDto2.setSellerId(sellerId);
			preOrderReduceCatalogDto2.setPreOrderId(OrderID);
			
			
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			pList.add(preOrderReduceCatalogDto2);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			//商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Logger.verifyEquals(catalogNum-preOrderReduceCatalogDto.getBuyCount(), icatalogNum, "验证规格库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_029() {
		Logger.start(true, "普通现货商品,扣减库存  查询redis");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 100000000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			int activityNum=100000000;
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			System.out.println(catalogs.toString());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, activityNum,"10");
			//添加秒杀商品数据
			ProductManagerCallServiceV2.addSecKillStock(activityId,productId, sellerId, true);
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			Long OrderID = System.currentTimeMillis();
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(activityId);
			preOrderReduceCatalogDto.setBuyCount(40);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
			RedisDriver rd = new RedisDriver("group1",EnvSetup.getSystemUrl("sentinel"));
			String key="SecStock:"+aids.get(0)+":"+catalogs.get(0);
			Logger.comment("获取redis，key为："+key+"值为："+rd.getValue(key));
			int stock=Integer.parseInt(rd.getValue(key));
			Logger.verifyEquals(stock, activityNum-preOrderReduceCatalogDto.getBuyCount(), "验证活动库存");
			
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(activityNum, istocknum, "验证活动库存没变，因为job未同步");
//			//发送同步指令SyncActivityProduct
//			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
//			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			if(joa.size()==0){
//				Thread.sleep(5000);
//				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
//			}
//			joa.forEach(ele->{
//				Logger.debug(ele.toString());
//			});
			
			
			Thread.sleep(5000);
			Integer istocknum1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(stock, istocknum1, "验证job同步数据库与reids一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_030() {
		Logger.start(true, "普通现货商品,扣减库存过多  查询redis");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			int activityNum=100;
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			System.out.println(catalogs.toString());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, activityNum,"10");
			//添加秒杀商品数据
			ProductManagerCallServiceV2.addSecKillStock(activityId,productId, sellerId, true);
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			
			Long OrderID = System.currentTimeMillis();
			PreOrderReduceCatalogDtoV2 preOrderReduceCatalogDto = new PreOrderReduceCatalogDtoV2();
			preOrderReduceCatalogDto.setActivityId(activityId);
			preOrderReduceCatalogDto.setBuyCount(200);
			preOrderReduceCatalogDto.setBuyerId(buyerId);
			preOrderReduceCatalogDto.setCatalogId(catalogs.get(0));
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setSellerId(sellerId);
			preOrderReduceCatalogDto.setPreOrderId(OrderID);
			List<PreOrderReduceCatalogDtoV2> pList = new ArrayList<PreOrderReduceCatalogDtoV2>();
			pList.add(preOrderReduceCatalogDto);
			reduceStockListForPreOrderBean.setCatalogList(pList);
			reduceStockListForPreOrderCall.setData(reduceStockListForPreOrderBean);
			reduceStockListForPreOrderCall.callService();
			String Code = reduceStockListForPreOrderCall.getString("Code");
			Logger.verifyEquals("400", Code, "验证Code");
			
			RedisDriver rd = new RedisDriver("group1",EnvSetup.getSystemUrl("sentinel"));
			String key="SecStock:"+aids.get(0)+":"+catalogs.get(0);
			int stock=Integer.parseInt(rd.getValue(key));
			Logger.verifyEquals(stock, activityNum, "验证活动库存");
			Logger.comment("获取redis，key为："+key+"值为："+rd.getValue(key));
			
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(activityNum, istocknum, "验证活动库存没变，因为job未同步");
			//验证两秒后job同步数据库与reids一致
			Thread.sleep(2000);
			Integer istocknum1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(stock, istocknum1, "验证job同步数据库与reids一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	private void initProductaddactivity(int activityId, String productId, List<String> catalogList) {
		// TODO 自动生成的方法存根
		
	}

	public List<CatalogDto> setCatalogList(List<CatalogDto>	catalogDtos, int userId) throws IOException {
		listagentTypeBean listagentTypeBean = GodmchManageCallService.InitlistgentTypeBean(userId);
		List<AgentTypeVo> agentTypeVos = GodmchManageCallService.listgentTypeCall(listagentTypeBean).getAgentTypes();
		catalogDtos.forEach(p -> {
			List<AgentPriceDto> agentPriceDtos1 = new ArrayList<>();
			agentTypeVos.forEach(x -> {
				AgentPriceDto agentPriceDto = new AgentPriceDto();
				agentPriceDto.setAgentTypeId(x.getAgentType());
				double price = Double.parseDouble(1 + TestDataManager.getRandomNum(2));
				agentPriceDto.setAgentPrice(price);
				agentPriceDtos1.add(agentPriceDto);
			});
			p.setAgentPriceList(agentPriceDtos1);
		});
		return catalogDtos;
	}

	
}
